package cn.tedu.egnotice0806.controller;

import cn.tedu.egnotice0806.base.response.JsonResult;
import cn.tedu.egnotice0806.mapper.NoticeMapper;
import cn.tedu.egnotice0806.pojo.dto.NoticeAddParam;
import cn.tedu.egnotice0806.pojo.entity.Notice;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.slf4j.XSlf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/v1/notice/")
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;

    @PostMapping("add")
    public JsonResult addNotice(@RequestBody NoticeAddParam noticeAddParam){
        log.debug("添加资讯："+noticeAddParam);
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam,notice);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        notice.setUserId(1L);
        log.debug("准备插入数据库："+notice);
        noticeMapper.insertNotice(notice);
        return JsonResult.ok();
    }
}
